package com.program.facesigninsystem.service.impl;

import com.program.facesigninsystem.dao.IClassesDao;
import com.program.facesigninsystem.dao.IUserClassDao;
import com.program.facesigninsystem.entity.Classes;
import com.program.facesigninsystem.entity.SignInList;
import com.program.facesigninsystem.service.IClassesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ClassesService implements IClassesService {
    @Autowired
    private IClassesDao iClassesDao;
    @Autowired
    private IUserClassDao iUserClassDao;

    @Override
    public void insertClasses(String cid,String name,int r_count,int t_count,String tid,String createTime) {
        iClassesDao.insertClasses(cid,name,r_count,t_count,tid,createTime);
    }

    @Override
    public Classes selectClass(String cid) {
        Classes classes = iClassesDao.selectClass(cid);
        return classes;
    }

    @Override
    public void updateAddCount(String cid) {
        iClassesDao.updateAddCount(cid);
    }

    @Override
    public List<Classes> selectClassListByTid(String tid) {
        List<Classes> classes = iClassesDao.selectClassListByTid(tid);
        return classes;
    }

    @Override
    public void updateClassTCount(String cid,int t_count) {
        iClassesDao.updateClassTCount(cid,t_count);
    }

    @Override
    public void deleteClass(String cid) {
        Classes classes=iClassesDao.selectClass(cid);
        if(classes.getR_count()!=0) {
            iUserClassDao.deleteUserList(cid);
        }
        iClassesDao.deleteClassById(cid);
    }

    @Override
    public void updateSubCount(String cid) {
        iClassesDao.updateSubCount(cid);
    }

    @Override
    public String selectTidByCid(String cid) {
        return iClassesDao.selectTidByCid(cid);
    }

    @Override
    public void insertSignInList(String uid, String filePath, String fileName, String url) {
        iClassesDao.insertSignInList(uid, filePath, fileName, url);
    }

    @Override
    public List<SignInList> selectSignInListByUid(String uid) {
        return iClassesDao.selectSignInListByUid(uid);
    }

    @Override
    public void deleteSignInList(String uid, int id) {
        iClassesDao.deleteSignInList(uid,id);
    }

    @Override
    public SignInList selectSignInList(int id) {
        return iClassesDao.selectSignInList(id);
    }
}
